package com.example.f8399.testdemo.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.example.f8399.testdemo.R;

/**
 * onCreateDialog 与 onCreateView 每次只能使用其中的一种，不能同时使用的，而且前者的优先级比后者的高
 * 但是使用方面没有什么区别，所以可以根据你的需要去使用
 */

public class MyDialogFragment2 extends DialogFragment implements View.OnClickListener {
    private static MyDialogFragment2 mFragment;
    private TextView mTv_title;
    private TextView mTv_context;

    public static MyDialogFragment2 newInstance() {
        if (mFragment == null) {
            mFragment = new MyDialogFragment2();
        }
        return mFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View rootView = LayoutInflater.from(this.getContext()).inflate(R.layout.dialog_my2, null);
        mTv_title = rootView.findViewById(R.id.tv_title);
        mTv_context = rootView.findViewById(R.id.tv_context);
        Button btn_ok = rootView.findViewById(R.id.btn_ok);
        Button btn_cancel = rootView.findViewById(R.id.btn_cancel);

        btn_ok.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);


        return rootView;
    }

    public TextView getTv_title() {
        return mTv_title;
    }

    public void setTv_title(TextView tv_title) {
        mTv_title = tv_title;
    }

    public TextView getTv_context() {
        return mTv_context;
    }

    public void setTv_context(TextView tv_context) {
        mTv_context = tv_context;
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.btn_ok:
                ToastUtils.showShort("hello");
                dismiss();
                break;
            case R.id.btn_cancel:
                ToastUtils.showShort("cancel");
                dismiss();
                break;
            default:

                break;
        }
    }
}
